# Disponivel no pacote de programas como: modelo_ode_minimo.py
#-*-encoding:utf-8-*-
from scipy import integrate
from numpy import *
import pylab as P

def Equations(t,y):
    """
    Define os sistema de EDOs calculando cada equacao
    com base no valor anterior e retornando as derivadas.
    """
    #---Cria vetor de equacoes--------------------
    eqs = ['3.0*y[0]-2.0*y[0]*y[1]','-2.0*y[1]+y[0]*y[1]']
    Neq=len(eqs)
    ydot = zeros((Neq),'d')
    for k in xrange(Neq):
        ydot[k] = eval(eqs[k])
    return ydot

if __name__=="__main__":
    r = integrate.ode(Equations).set_integrator('vode')
    r.set_initial_value([1,1],0)
    tf = 10 #tempo final
    dt = 0.1
    t = []
    y = []
    while r.successful() and r.t <= tf:
        r.integrate(r.t+dt)
        t.append(r.t)
        y.append(r.y)
    print r.y
    #Plota resultados
    P.plot (t,array(y)[:,0], 'v-',t,array(y)[:,1],'o-')
    P.title('Integrador Vode')
    P.legend(['Presa','Predador'])
    P.savefig('lv2.png',dpi=400)
    P.show()

